
cd "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/Pela project"

use "../LASA/Datos/all_countries3_withcontext.dta", clear
rename pais country_name
rename legis year

drop _merge

merge m:1 country_name year using "v_dem_LA.dta"

* drop cases in vdem but not in pela
drop if _merge==2

*Colombia does not have year
drop if _merge==1

drop _merge


merge m:1 country_name year using "context_pela.dta", keep(match)




* recode the same-sex marriage question
* moral conservative
gen pro_ssm= 0 if val_ssm <=3
* moral middle
replace pro_ssm=1 if val_ssm <=7 & val_ssm>3
* moral progressive
replace pro_ssm=2 if val_ssm >7
replace pro_ssm=. if val_ssm >10
lab value pro_ssm pro_abort_lab

gen eco_moral4 = 1 if pro_ssm == 0 & pro_regulation2==0
replace eco_moral4 = 2 if pro_ssm == 0 & pro_regulation2==1
replace eco_moral4 = 3 if pro_ssm == 0 & pro_regulation2==2
replace eco_moral4 = 4 if pro_ssm == 1 & pro_regulation2==0
replace eco_moral4 = 5 if pro_ssm == 1 & pro_regulation2==1
replace eco_moral4 = 6 if pro_ssm == 1 & pro_regulation2==2
replace eco_moral4 = 7 if pro_ssm == 2 & pro_regulation2==0
replace eco_moral4 = 8 if pro_ssm == 2 & pro_regulation2==1
replace eco_moral4 = 9 if pro_ssm == 2 & pro_regulation2==2
lab value eco_moral4 eco_moral2_lab


lab variable pid_p "PID"

gen eco_moral_recode=.

replace eco_moral_recode=eco_moral2
lab value eco_moral_recode eco_moral2_lab

******************************************
* volatility from PELA
eststo clear
eststo: mlogit party_family ib5.eco_moral_recode##i.vola_h i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) vola_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_vola_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) vola_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_vola_inter_effect.dta")



mlogit party_family ib5.eco_moral_recode i.vola_h i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) vola_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_vola_pela_effect.dta")

margins, at(eco_moral_recode=(1(1)9) vola_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_vola_pela_effect.dta")



* ENP from PELA

eststo: mlogit party_family ib5.eco_moral_recode##i.ENP_h i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) ENP_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_ENP_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) ENP_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_ENP_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.ENP_h i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) ENP_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_ENP_pela_effect.dta")

margins, at(eco_moral_recode=(1(1)9) ENP_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_ENP_pela_effect.dta")


* polarization from pela

eststo: eststo: mlogit party_family ib5.eco_moral_recode##i.polar_h i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) polar_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_polar_pela_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) polar_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_polar_pela_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.polar_h i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) polar_h=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_polar_pela_effect.dta")

margins, at(eco_moral_recode=(1(1)9) polar_h=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_polar_pela_effect.dta")

esttab using "context_pela.tex", drop(_cons *wave *pais_n*) order(*eco_moral_recode 1.vola_h 1.ENP_h 1.polar_h *eco_moral_recode#*) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Model 1" "Model 2") nobaselevels unstack nodepvars noomitted replace 
*********************************************************************
* clientelism
gen client=(v2xnp_client>0.5)
tab party_family if client==1

eststo clear

eststo: mlogit party_family ib5.eco_moral_recode##i.client i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) client=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_client_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) client=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_client_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.client i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) client=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_client_effect.dta")

margins, at(eco_moral_recode=(1(1)9) client=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_client_effect.dta")

*******
* poor economy
tab party_family if poor==1
tab party_family if poor==0

eststo: mlogit party_family ib5.eco_moral_recode##i.poor i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) poor=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_poor_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) poor=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_poor_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.poor i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) poor=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_poor_effect.dta")

margins, at(eco_moral_recode=(1(1)9) poor=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_poor_effect.dta")

*******
* low PSI

tab party_family if low_psi==1
tab party_family if low_psi==0

eststo: mlogit party_family ib5.eco_moral_recode##i.low_psi i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) low_psi=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_psi_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) low_psi=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_psi_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.low_psi i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) low_psi=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_psi_effect.dta")

margins, at(eco_moral_recode=(1(1)9) low_psi=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_psi_effect.dta")

esttab using "context_client_eco_psi.tex", drop(_cons *wave *pais_n*) order(*eco_moral_recode 1.client 1.poor 1.low_psi *eco_moral_recode#*) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Model 1" "Model 2") nobaselevels unstack nodepvars noomitted replace 
*******
* polarization from vdem
eststo clear
gen polar=(v2cacamps>0)
tab party_family if polar==1

eststo: mlogit party_family ib5.eco_moral_recode##i.polar i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) polar=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_polar_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) polar=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_polar_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.polar i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) polar=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_polar_effect.dta")

margins, at(eco_moral_recode=(1(1)9) polar=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_polar_effect.dta")
*******

* political exclusion
gen exclu=(v2xpe_exlecon>0.5)

eststo: mlogit party_family ib5.eco_moral_recode##i.exclu i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) exclu=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_exclu_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) exclu=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_exclu_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.exclu i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) exclu=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_exclu_effect.dta")

margins, at(eco_moral_recode=(1(1)9) exclu=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_exclu_effect.dta")
*******

* higher PID from LAPOP
eststo: mlogit party_family ib5.eco_moral_recode##i.high_pid i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) high_pid=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_pid_h_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) high_pid=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_pid_h_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.high_pid i.age_party_recode age N_party_member female education religious i.pais_n i.wave, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) high_pid=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_pid_h_effect.dta")

margins, at(eco_moral_recode=(1(1)9) high_pid=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_pid_h_effect.dta")

esttab using "context_polar_exclu_pid.tex", drop(_cons *wave *pais_n*) order(*eco_moral_recode 1.polar 1.exclu 1.high_pid *eco_moral_recode#*) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Model 1" "Model 2") nobaselevels unstack nodepvars noomitted replace 
*******
* party-system religion
gen reli=(v2xpas_religion>0.5)
eststo clear

eststo: mlogit party_family ib5.eco_moral_recode##i.reli i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) reli=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_reli_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) reli=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_reli_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.reli i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) reli=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_reli_effect.dta")

margins, at(eco_moral_recode=(1(1)9) reli=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_reli_effect.dta")
*******


* not working
mlogit party_family ib5.eco_moral_recode##i.poor_edu i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)
margins, at(eco_moral_recode=(1(1)9) poor_edu=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_poor_edu_inter_efffect.dta")

*******

* legislative party cohesion

eststo: mlogit party_family ib5.eco_moral_recode##i.cohesion i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) cohesion=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_cohesion_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) cohesion=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_cohesion_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.cohesion i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) cohesion=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_cohesion_effect.dta")

margins, at(eco_moral_recode=(1(1)9) cohesion=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_cohesion_effect.dta")
*******

*political stability
eststo: mlogit party_family ib5.eco_moral_recode##i.stable i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) stable=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_stable_inter_effect.dta")

margins, at(eco_moral_recode=(1(1)9) stable=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_stable_inter_effect.dta")

mlogit party_family ib5.eco_moral_recode i.stable i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral_recode=(1(1)9) stable=(0 1)) predict(outcome(3)) saving("model1_pred_prob_right_stable_effect.dta")

margins, at(eco_moral_recode=(1(1)9) stable=(0 1)) predict(outcome(1)) saving("model1_pred_prob_left_stable_effect.dta")

esttab using "context_reli_cohesion_stab.tex", drop(_cons *wave *pais_n*) order(*eco_moral_recode 1.reli 1.cohesion 1.stable *eco_moral_recode#*) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Model 1" "Model 2") nobaselevels unstack nodepvars noomitted replace 


eststo clear
* use continuous GDP per capita
eststo: mlogit party_family ib5.eco_moral_recode##c.e_gdppc i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)


esttab using "context_gdp_continuous.tex", drop(_cons *wave *pais_n*) order(*eco_moral_recode  *eco_moral_recode#*) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Model 1 (with GDP per capita)") nobaselevels unstack nodepvars noomitted replace 


